package com.bocai.yuweiwangluo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.bean.MessageListBean;


public class MessageYesReadAdapter extends BaseAdapter{
    private Context context;
    private MessageListBean messageListBean;
    public MessageYesReadAdapter(Context context,MessageListBean messageListBean){
        this.context=context;
        this.messageListBean=messageListBean;
    }
    public void addData(MessageListBean bean){
        messageListBean.getData().addAll(bean.getData());
        this.notifyDataSetChanged();

    }
    @Override
    public int getCount() {
        return messageListBean.getData().size();
    }

    @Override
    public Object getItem(int position) {
        return messageListBean.getData().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_message_list,null);
            viewHolder.tvFrom=(TextView)convertView.findViewById(R.id.tv_message_from);
            viewHolder.tvContent=(TextView)convertView.findViewById(R.id.tv_message_content);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvFrom.setText(messageListBean.getData().get(position).getTitle());
        if(messageListBean.getData().get(position).getContent()!=null){
            viewHolder.tvContent.setText(messageListBean.getData().get(position).getContent());
        }else{
            viewHolder.tvContent.setText("");
        }
        return convertView;
    }


    public class ViewHolder {
        TextView tvFrom;
        TextView tvContent;


    }
}
